package cn.com.se.多线程.async;

import ch.qos.logback.classic.Logger;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;
import org.slf4j.LoggerFactory;


public class AsyncTest {

    static AsyncTest asyncTest = new AsyncTest();
    private static Logger log = (Logger) LoggerFactory.getLogger(AsyncTest.class);


    public static void main(String[] args) {
        log.info("线程还未启动----无锁");
        System.out.println(Integer.toHexString(asyncTest.hashCode()));
        log.info(ClassLayout.parseInstance(asyncTest).toPrintable());


        log.info("-----------------------------------------");

        // 偏向锁  首选判断是否可偏向  判断是否偏向了 拿到当前的id 通过cas 设置到对象头
        synchronized (asyncTest) {
            log.info("name:" + Thread.currentThread().getName());
            // 有锁,是一把偏向锁
            log.info(ClassLayout.parseInstance(asyncTest).toPrintable());
        }
    }
}
